var myApp = new Framework7({
    modalTitle: "闪点提示",
    modalButtonOk: "确定",
    modalButtonCancel: "取消",
    modalPreloaderTitle: "加载中...",
    modalUsernamePlaceholder: "用户名",
    modalPasswordPlaceholder: "密码"
});


var $$ = Dom7;

var mainView = myApp.addView('.view', {

});
$$(document).on('pageInit', function (e) {
    var page = e.detail.page;

    if (page.name === 'index') {
        var pickerInline = myApp.picker({
            container: '#picker-date-container',
            toolbar: false,
            rotateEffect: true,
            cols: [
                {
                    values: ('5 6 7 8 9 10 11 12 13 14 15').split(' '),
                    displayValues: ('500元 600元 700元 800元 900元 1000元 1100元 1200元 1300元 1400元 1500元').split(' '),
                    textAlign: 'center',
                    width:170
                },
                {
                    values: ['7天','8天','9天','10天','11天','12天','13天','14天','15天','16天','17天','18天','19天','20天','21天','22天','23天','24天','25天','26天','27天','28天','29天','30天'],
                    textAlign: 'right',
                    width:170
                },
            ],
            onChange:function(p, values, displayValues){
                var pikervalue1=p.cols[0].displayValue;//获取选取的项目
                var pikervalue2=p.cols[1].displayValue;//获取选取的项目
                if(window.localStorage){
                    localStorage.setItem('money',pikervalue1);//存储所选钱款
                    localStorage.setItem('Numberday',pikervalue2);//存储所选天数
                }
                localStorage.getItem("money");//获取所选钱款的值
                localStorage.getItem("Numberday");//获取所选天数的值
            }
        });
    }
})
var pickerInline = myApp.picker({
    container: '#picker-date-container',
    toolbar: false,
    rotateEffect: true,
    cols: [
        {
            values: ('5 6 7 8 9 10 11 12 13 14 15').split(' '),
            displayValues: ('500元 600元 700元 800元 900元 1000元 1100元 1200元 1300元 1400元 1500元').split(' '),
            textAlign: 'center',
            width:170
        },
        {
            values: ['7天','8天','9天','10天','11天','12天','13天','14天','15天','16天','17天','18天','19天','20天','21天','22天','23天','24天','25天','26天','27天','28天','29天','30天'],
            textAlign: 'right',
            width:170
        },
    ],
    onChange:function(p, values, displayValues){
        var pikervalue1=p.cols[0].displayValue;//获取选取的项目
        var pikervalue2=p.cols[1].displayValue;//获取选取的项目
        if(window.localStorage){
            localStorage.setItem('money',pikervalue1);//存储所选钱款
            localStorage.setItem('Numberday',pikervalue2);//存储所选天数
        }
        localStorage.getItem("money");//获取所选钱款的值
        localStorage.getItem("Numberday");//获取所选天数的值
    }
});


$$(".skip").click(function(){
    if(localStorage.shuju){//判断本地存储有无数据
        $$(this).attr("href",$$(this).attr("hraf"));
    }else{
        $$(this).attr("href","login.html");
    }
})
$$(document).on('pageInit', '.page[data-page="index"]', function (e) {
    $$(".skip").click(function(){
        if(localStorage.shuju){//判断本地存储有无数据
            $$(this).attr("href",$$(this).attr("hraf"));
        }else{
            $$(this).attr("href","login.html");
        }
    });
    /*轮播图效果*/
    var mySwiper = myApp.swiper('.swiper-container', {
        pagination:'.swiper-pagination',
        speed:300,
    });

})
$$(document).on('pageInit', '.page[data-page="Set-up"]', function (e) {
    $$('.install').on('click', function () {
        myApp.confirm('确定退出登录吗?', '闪点借贷', function () {
                localStorage.removeItem('shuju');  /*点击确定按钮的回调*/
            },
            function () {
                /*点击取消按钮的回调*/
            }
        );
    });
})
$$(document).on('pageInit', '.page[data-page="Apply"]', function (e) {
    $$('.next').on('click', function () {//下一步按钮
        $$(".apply li span").each(function() {
            //若当前span未填写，则alert提醒
            if(!this.value || this.value.trim() == "未完善") {
                var label = this.previousElementSibling;
                myApp.alert('闪点借贷提醒您',label.innerText + "未填写");
                check = false;
                return false;
            }else{
                check=true;
            }
        }); //校验通过，继续执行业务逻辑
        if(check){
            myApp.alert('闪点借贷提醒您','验证通过!');
        }
    });
})
$$(document).on('pageInit', '.page[data-page="Confirmation-loan"]', function (e) {
    $$('.create-popup').on('click', function () {
        var popupHTML = '<div class="popup my-popup">'+
            '<div class="content-block">'+
            '<p>您申请的已经'+'<b>提交审核</b>'+'!'+'<br>'+'我们稍后将通知您审核结果</p>'+
            '<img src="images/sucess@2x.png" alt="">'+
            '<p><a href="#" class="close-popup"></a></p>'+
            '</div>'+
            '</div>'

        myApp.popup(popupHTML);
    });
    $$('.close-popup').on('click', function () {
        myApp.closeModal(popup);
    });
})

/*轮播图效果*/
var mySwiper = myApp.swiper('.swiper-container', {
    pagination:'.swiper-pagination',
    speed:300,
});
$$(document).on('pageInit', '.page[data-page="identity"]', function (e) {
    /*教育程度下拉效果*/
    var pickerEducation = myApp.picker({
        input: '#Education',
        rotateEffect: true,
        toolbarTemplate:
        '<div class="toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link toolbar-randomize-link"></a>' +
        '</div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        cols: [
            {
                textAlign: 'center',
                values: ['高中以下', '高中', '中专', '大专', '本科及以上']
            }
        ]
    });
    /*婚姻状况下拉效果*/
    var pickerMarriage = myApp.picker({
        input: '#Marriage',/*获取下拉菜单id*/
        updateValuesOnTouchmove:false,
        toolbarTemplate:
        '<div class="toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link toolbar-randomize-link"></a>' +
        '</div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        cols: [
            {
                textAlign: 'center',
                values: ['未婚', '已婚未育', '已婚已育', '离异', '其他']
            }
        ]
    });
})
$$(document).on('pageInit', '.page[data-page="work"]', function (e) {
    /*月薪下拉效果*/
    var pickersalary = myApp.picker({
        input: '#monthly-salary',/*获取下拉菜单id*/
        rotateEffect: true,/*旋转效果*/
        toolbarTemplate: /*模块代码*/
        '<div class="toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link toolbar-randomize-link"></a>' +
        '</div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        cols: [/*数据接收*/
            {
                textAlign: 'center',
                values: ['2000以内', '2000-3000', '3000-5000', '5000-8000', '8000-12000',"12000以上"]
            }
        ]
    });
    /*入职时间下拉效果*/
    var pickerTime = myApp.picker({
        input: '#Time',/*获取下拉菜单id*/
        rotateEffect: true,/*旋转效果*/
        toolbarTemplate: /*模块代码*/
        '<div class="toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link toolbar-randomize-link"></a>' +
        '</div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        cols: [/*数据接收*/
            {
                textAlign: 'left',
                values: ['1998年', '1999年', '2000年', '2001年', '2002年',"2003年",'2004年',"2005年",'2006年',"2007年","2008年",'2009年',"2010年",'2011年',"2012年","2013年","2014年",'2015年',"2016年",'2017年']
            },
            {
                textAlign: 'right',
                values: ['1月', '2月', '3月', '4月', '5月',"6月", '7月', '8月', '9月', '10月', '11月',"12月"]
            }
        ]
    })
    // 扩展API加载完毕后调用onPlusReady回调函数
    document.addEventListener( "plusready", onPlusReady, false );
    // 扩展API加载完毕，现在可以正常调用扩展API
    function onPlusReady() {
        console.log("plusready");
    }
    // 获取工作证明
    $$(".captureImage4").click(function(){
        var cmr = plus.camera.getCamera();
        var res = cmr.supportedImageResolutions[0];
        var fmt = cmr.supportedImageFormats[0];
        console.log("Resolution: "+res+", Format: "+fmt);
        cmr.captureImage( function( path ){
                alert( "Capture image success: " + path );
            },
            function( error ) {
                alert( "Capture image failed: " + error.message );
            },
            {resolution:res,format:fmt}
        );
    })
})
$$(document).on('pageInit', '.page[data-page="contact"]', function (e) {
    /*与本人关系效果*/
    var pickerrelationship = myApp.picker({
        input: '#relationship',/*获取下拉菜单id*/
        rotateEffect: true,/*旋转效果*/
        toolbarTemplate: /*模块代码*/
        '<div class="toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link toolbar-randomize-link"></a>' +
        '</div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        cols: [/*数据接收*/
            {
                textAlign: 'center',
                values: ['配偶', '父亲', '母亲', '弟弟', '哥哥',"妹妹","姐姐"]
            }
        ]
    });
})
$$(document).on('pageInit', '.page[data-page="auto"]', function (e) {
    /*支付操作*/
    var pickersalary = myApp.picker({
        input: '#salary',/*获取下拉菜单id*/
        rotateEffect: true,/*旋转效果*/
        toolbarTemplate: /*模块代码*/
        '<div class="toolbar">' +
        '<div class="toolbar-inner">' +
        '<div class="left">' +
        '<a href="#" class="link toolbar-randomize-link"></a>' +
        '</div>' +
        '<div class="right">' +
        '<a href="#" class="link close-picker">确定</a>' +
        '</div>' +
        '</div>' +
        '</div>',
        cols: [/*数据接收*/
            {
                textAlign: 'center',
                values: ['支付宝', '微信']
            }
        ],
        onChange:function(p, values, displayValues){
            console.log(p.value.join());//获取选取的项目
        }
    });
})
$$(document).on('pageInit', '.page[data-page="login"]', function (e) {
    $$("#input_example .btn").click(function(){
        $$("#input_example input").each(function() {
            //若当前input为空，则alert提醒
            if(!this.value || this.value.trim() == "") {
                var label = this.previousElementSibling;
                myApp.alert('闪点借贷提醒您',label.innerText + "不允许为空");
                check = false;
                return false;
            }else{
                check=true;
            }
        }); //校验通过，继续执行业务逻辑
        if(check){
            myApp.alert('闪点借贷提醒您','验证通过!');
        }
        if(window.localStorage){
            // console.log(localStorage);
            localStorage.setItem('shuju',$$("#phone").val());
            localStorage.setItem('pwd',$$('#pwd').val());
        }
    })
})
$$(document).on('pageInit', '.page[data-page="register"]', function (e) {
    $$("#input_example .btn").click(function(){
        $$("#input_example input").each(function() {
            //若当前input为空，则alert提醒
            if(!this.value || this.value.trim() == "") {
                var label = this.previousElementSibling;
                myApp.alert('闪点借贷提醒您',label.innerText + "不允许为空");
                check = false;
                return false;
            }else{
                check=true;
            }
        }); //校验通过，继续执行业务逻辑
        if(check){
            myApp.alert('闪点借贷提醒您','验证通过!');
        }
    })
    var a=true;
    $$("#yzm").click(function(){
        if(a){
            a=false;
            $$(this).html("60秒");
            $$.ajax({
                url: '',
                statusCode: {

                }
            })
            var timer=null;
            timer=setInterval(function(){
                var yzm=parseInt($$("#yzm").html());
                yzm--;
                $$("#yzm").html(parseInt(yzm)+"秒");
                if(parseInt(yzm)<=0){
                    clearInterval(timer);
                    $$("#yzm").html("获取验证码");
                    a=true;
                }
            },1000);
        }
    });
})
$$(document).on('pageInit', '.page[data-page="password"]', function (e) {
    $$("#input_modify .btn").click(function(){
        $$("#input_modify input").each(function() {
            //若当前input为空，则alert提醒
            if(!this.value || this.value.trim() == "") {
                var label = this.previousElementSibling;
                myApp.alert('闪点借贷提醒您',label.innerText + "不允许为空");
                check = false;
                return false;
            }else{
                var modify1=$$("#modify1").value;
                var modify2=$$("#modify2").value;
                if(modify1 == modify2){
                    check = true;
                }
            }
        }); //校验通过，继续执行业务逻辑
        if(check){
            myApp.alert('闪点借贷提醒您','验证通过!');
        }
    })
})
$$(document).on('pageInit', '.page[data-page="my"]', function (e) {
    $$('.create-popup2').on('click', function () {
        var popupHTML = '<div class="popup popup2">'+
            '<div class="content-block">'+
            '<h4>分享至</h4>'+
            '<ul>'+
            '<li><a href="#" title="分享到QQ好友"><img src="images/ic_share_qq_n1.png" alt=""><span>QQ好友</span></a></li>'+
            '<li><a href="#" title="分享到微信"><img src="images/ic_share_wechat_n1.png" alt=""><span>微信好友</span></a></li>'+
            '<li><a href="#" title="分享到新浪微博"><img src="images/ic_share_microblogsina_n1.png" alt=""><span>微博</span></a></li>'+
            '<li><a href="#" title="分享到QQ空间"><img src="images/ic_share_qqzone_n.png" alt=""><span>QQ空间</span></a></li>'+
            '<li><a href="javascript:void(0)"><img src="images/ic_share_message_n.png" alt=""><span>短信</span></a></li>'+
            '</ul>'+
            '<p><a href="#" class="close-popup">取消</a></p>'+
            '</div>'+
            '</div>'
        myApp.popup(popupHTML);
    });
    $$('.close-popup').on('click', function () {
        myApp.closeModal(popup);
    });
})
$$(document).on('pageInit', '.page[data-page="identity"]', function (e) {
// 扩展API加载完毕后调用onPlusReady回调函数 
    document.addEventListener( "plusready", onPlusReady, false );
// 扩展API加载完毕，现在可以正常调用扩展API 
    function onPlusReady() {
        console.log("plusready");
    }
// 获取身份证正面
    $$(".captureImage1").click(function(){
        var cmr = plus.camera.getCamera();
        var res = cmr.supportedImageResolutions[0];
        var fmt = cmr.supportedImageFormats[0];
        console.log("Resolution: "+res+", Format: "+fmt);
        cmr.captureImage( function( path ){
                alert( "Capture image success: " + path );
            },
            function( error ) {
                alert( "Capture image failed: " + error.message );
            },
            {resolution:res,format:fmt}
        );
    })
// 获取身份证反面
    $$(".captureImage2").click(function(){
        var cmr = plus.camera.getCamera();
        var res = cmr.supportedImageResolutions[0];
        var fmt = cmr.supportedImageFormats[0];
        console.log("Resolution: "+res+", Format: "+fmt);
        cmr.captureImage( function( path ){
                alert( "Capture image success: " + path );
            },
            function( error ) {
                alert( "Capture image failed: " + error.message );
            },
            {resolution:res,format:fmt}
        );
    })
// 获取人脸
    $$(".captureImage3").click(function(){
        var cmr = plus.camera.getCamera();
        var res = cmr.supportedImageResolutions[0];
        var fmt = cmr.supportedImageFormats[0];
        console.log("Resolution: "+res+", Format: "+fmt);
        cmr.captureImage( function( path ){
                alert( "Capture image success: " + path );
            },
            function( error ) {
                alert( "Capture image failed: " + error.message );
            },
            {resolution:res,format:fmt}
        );
    })
})